<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    
</head>
<body>
    <script>  
         /* 
            解题思路：
               1.分析需求
               2.编写代码
               3，调试代码
         */
        // 将数组  ['关羽', '张飞', '程咬金','吕布']  转换为字符串
        var arr = ['关羽', '张飞', '程咬金','吕布'];
        let result = '[';
        /* for(let i =0;i <arr.length;i++){
            if(i==arr.length-1){
                result = result+'\''+arr[i]+'\'';
            }else{
                result = result+'\''+arr[i]+'\''+', ';
            }
        } */

        /* for(let index in arr){
            if(index==arr.length-1){
                result = result+'\''+arr[index]+'\'';
            }else{
                result = result+'\''+arr[index]+'\''+', ';
            }
        } */

         for(let item of arr){
            if(item==arr[arr.length-1]){
                result = result+'\''+item+'\'';
            }else{
                result = result+'\''+item+'\''+', ';
            }
         }
        result = result +']';
        console.log(result);

    </script>
</body>
</html>